package com.example.jiangkt.ergongyi.util;

import android.content.Context;
import android.content.SharedPreferences;

import org.jasypt.util.text.BasicTextEncryptor;

/**
 * Created by jiangkt on 2018/3/10.
 */

public class UserUtil {

    public static void saveLoginInfo(Context context, String username, String password) {
        // 获取SharedPreferences对象
        SharedPreferences sharedPre = context.getSharedPreferences("config", Context.MODE_PRIVATE);
        // 获取Editor对象
        SharedPreferences.Editor editor = sharedPre.edit();
        // 设置参数
        editor.putString("username", username);
        editor.putString("password", password);
        // 提交
        editor.commit();
    }

    /**
     * 加密
     *
     * @param password
     * @return
     */
    public static String encrypt(String password) {
        BasicTextEncryptor textEncryptor = new BasicTextEncryptor();
        textEncryptor.setPassword("password");
        return textEncryptor.encrypt(password);
    }

    /**
     * 解密
     *
     * @param password
     * @return
     */
    public static String decrypt(String password) {
        BasicTextEncryptor textEncryptor = new BasicTextEncryptor();
        textEncryptor.setPassword("password");
        return textEncryptor.decrypt(password);
    }
}
